package com.geek.ch06.anno;

import com.geek.entity.Item;
import com.geek.entity.OrderDetails;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Desc TODO
 * @Author
 * @Date 2025/11/20
 */
public interface OrderDetailMapper {

    //通过订单ID，查询其所有的订单明细
    @Select("select * from orderdetail where orders_id = #{oid}")
    @Results({
            @Result(id = true , property = "id" , column = "id"),
            @Result(property = "items" , column = "items_id" ,javaType = Item.class ,
                one = @One(select = "com.geek.ch06.anno.ItemsMapper.findItemsById"))
    })
    public List<OrderDetails> findDetailsByOid(int oid) ;

    //<!-- 注解方式作业2：每个订单中包含的商品信息  OM -->
    @Select("select * from orderdetail where orders_id = #{id}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "ordersId",column = "orders_id"),
            @Result(property = "itemsId",column = "items_id"),
            @Result(property = "itemsNum",column = "items_num"),
            @Result(property = "items",column = "items_id",javaType = Item.class,
                    one = @One(select = "com.geek.ch06.anno.ItemsMapper.selectItem"))
    })
    List<OrderDetails> selectOrderDetailAndItemById(Integer id);
}
